package itheima.moc.myreflect4;

import java.lang.reflect.Field;

public class ReflectDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException {
//        method1();
        Class clazz = Class.forName("itheima.moc.myreflect4.Student");
        Field money = clazz.getDeclaredField("money");
        money.setAccessible(true);
        Student student = (Student) clazz.newInstance();
        Object o = money.get(student);
        System.out.println(o);
    }

    private static void method1() throws ClassNotFoundException, NoSuchFieldException, InstantiationException, IllegalAccessException {
        Class clazz = Class.forName("itheima.moc.myreflect4.Student");
        Field field = clazz.getField("name");
        Student student = (Student) clazz.newInstance();
        field.set(student, "ZH");
        System.out.println(student);
    }
}
